﻿using System;
using System.Web.Mvc;
using Icms.Core.Model;
using Icms.Core.Repository;
using Omu.Awesome.Mvc;

namespace Icms.WebUI.Controllers
{
    public class PersonIdLookupController : LookupController
    {
        private readonly IRepo<Person> r;

        public PersonIdLookupController(IRepo<Person> r)
        {
            this.r = r;
        }

        [HttpPost] 
        public ActionResult Search(string search)
        {
            return  View(@"Awesome\LookupList", r.Where(o => o.FirstName.StartsWith(search)));
        }

        public ActionResult Get(Guid id)
        {
            var o = r.Get(id);
            var s = o != null ? string.Format("{0} {1} {2}", o.FirstName, o.LastName, o.SurName) : "null";
            return Content(s);
        }
    }
}